module argument_passing ();

// argument pass by value 按值传递
function automatic int add(int a, int b);
    return a + b;
endfunction

// argument pass by reference 按引用传递
function automatic int sum(ref int arr[]);
    int total = 0;
    foreach (arr[i]) begin
        total += arr[i];
    end
    return total;
endfunction

// argument pass by name 按名称传递
function automatic int multiply(int a, int b);
    return a * b;
endfunction

// default argument values 默认参数
function automatic int calculate(int a, int b = 10, int c = 5);
    return a + b * c;
endfunction


initial begin
    begin
        int a = 1, b = 3;
        $display("argument pass by value: add(%0d, %0d) = %0d", a, b, add(a, b));
    end
    begin
        int arr[] = '{1, 2, 3, 4, 5};
        $display("argument pass by reference:sum(%p) = %0d", arr, sum(arr));
    end
    begin
        $display("argument pass by name: multiply(.a(2), .b(2)) = %0d", multiply(.a(2), .b(2)));
    end
    begin
        $display("default argument values: calculate(2) = %0d", calculate(2));
    end
end

endmodule
